package com.fjwt.gz.sync.notify;

import com.fjwt.gz.core.utils.SpringBeansUtil;
import com.fjwt.gz.interfaces.ChannelCouponWriteService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;

@Slf4j
@Service
public class LklsCouponWriteOffNotifyService {

    private static final Logger lklsPayLogger = LoggerFactory.getLogger("lklsPay");
    public  String lklspaySyncPayOrder(HttpServletRequest request) {
        String ifCode = "lklspay";
        String result = "false";

        String logPrefix = "进入[" + ifCode + "]卡券核销回调";
        lklsPayLogger.info("===== {} =====", logPrefix);

        try {
            // 参数有误
            if (StringUtils.isEmpty(ifCode)) {
                lklsPayLogger.info(logPrefix + "回调参数有误,ifcode不存在,返回的信息是：{}", result);
                return result;
            }

            //查询支付接口是否存在
            ChannelCouponWriteService channelCouponWriteService = SpringBeansUtil.getBean(ifCode + "CouponWriteService", ChannelCouponWriteService.class);

            // 支付通道接口实现不存在
            if (channelCouponWriteService == null) {
                lklsPayLogger.info(logPrefix + "支付通道接口实现不存在,返回的信息是：{}", result);
                return "false";
            }

            //解析参数
            Map<String, Object> map = channelCouponWriteService.paraseParamters(request);

            result = channelCouponWriteService.addNotifyRecord(map);
            lklsPayLogger.info(ifCode + "返回的信息是：{}", result);

            return result;
        } catch (Exception e) {
            lklsPayLogger.info(logPrefix + "系统异常：{}", e.getMessage());
            return "false";
        }
    }
}
